import { createRouter, createWebHashHistory } from "vue-router";

const base = [
  {
    path: "/",
    name: "root",
    redirect: "/login",
    meta: { layout: "blank" },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login/index.vue"),
    meta: { layout: "blank" },
  },
];

const error = {
  path: "/:pathMatch(.*)*",
  name: "NotFound",
  component: () => import("../views/error/index.vue"),
  meta: { layout: "blank" },
};

export const dynamic = [
  {
    path: "/home",
    name: "home",
    component: () => import("../views/recipe/index.vue"),
    meta: { layout: "content", title: "配方管理", icon: "list" },
  },
  {
    path: "/standard",
    name: "standard",
    redirect: "/standard/specs",
    meta: { layout: "content", title: "规范管理", icon: "list" },
    children: [
      {
        path: "/standard/specs",
        name: "specs",
        component: () => import("../views/specs/index.vue"),
        meta: { layout: "content", title: "包装规范", icon: "row" },
      },
      {
        path: "/standard/labels",
        name: "labels",
        component: () => import("../views/labels/index.vue"),
        meta: { layout: "content", title: "标签规范", icon: "build" },
      },
      {
        path: "/standard/check",
        name: "check",
        component: () => import("../views/check/index.vue"),
        meta: { layout: "content", title: "检测规范", icon: "build" },
      },
    ],
  },
  {
    path: "/system",
    name: "standard",
    redirect: "/standard/specs",
    meta: { layout: "content", title: "系统信息", icon: "list" },
    children: [
      {
        path: "/system/user",
        name: "system",
        component: () => import("../views/user/index.vue"),
        meta: { layout: "content", title: "用户管理", icon: "user" },
      },
      {
        path: "/system/logs",
        name: "logs",
        component: () => import("../views/logs/index.vue"),
        meta: { layout: "content", title: "日志管理", icon: "log" },
      },
      {
        path: "/system/config",
        name: "config",
        component: () => import("../views/config/index.vue"),
        meta: { layout: "content", title: "系统配置", icon: "system" },
      },
    ],
  },
];

const editRouter = [
  {
    path: "/edit/formula",
    name: "edit-formula",
    component: () => import("../views/editFormula/index.vue"),
    meta: { layout: "blank", title: "配方编辑", icon: "edit" },
  },
  {
    path: "/pdf/preview",
    name: "pdf-preview",
    component: () => import("../views/editFormula/preview-pdf/index.vue"),
    meta: { layout: "blank", title: "pdf预览", icon: "edit" },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...base, ...editRouter],
});

export default router;
